/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uk.ac.aber.compsci.se3920.groupA.Tests;

import java.util.ArrayList;
import java.util.Calendar;
import uk.ac.aber.compsci.se3920.groupA.Tests.MockTypes.ActiveParticipantPreference;
import uk.ac.aber.compsci.se3920.groupA.Tests.MockTypes.ExclusionRange;
import uk.ac.aber.compsci.se3920.groupA.Tests.MockTypes.Meeting;
import uk.ac.aber.compsci.se3920.groupA.Tests.MockTypes.MeetingCandidate;
import uk.ac.aber.compsci.se3920.groupA.Tests.MockTypes.Room;
import uk.ac.aber.compsci.se3920.groupA.Tests.Utils.Debug;

/**
 *
 * @author rob
 */
public class Tester {
    private Config config;
    private Setup setup;
    private String[] equip;
    

    public Tester() {
        /* 
         * Find start times and scores, for a meeting with the following attributes:
         * =========================================================================
         *  Equipment: Computer, Dictionary
         *  Meeting Duration: 3 Hours
         *  Meeting Attendance: 10
         *  Exclusion Set: 12:00 - 14:00
         */
        equip = new String[]{Config.EQUIP_COMPUTER, Config.EQUIP_DICTIONARY };
        config = new Config(3,10,equip);
        setup = new Setup(config);
        runTestsVerbose(config, setup, config.getMeeting());

        /* 
         * Find start times and scores, for a meeting with the following attributes:
         * =========================================================================
         ** Equipment: Computer, Projector
         *  Meeting Duration: 3 Hours
         *  Meeting Attendance: 10
         *  Exclusion Set: 12:00 - 14:00
         */
        equip = new String[]{Config.EQUIP_COMPUTER, Config.EQUIP_PROJECTOR };
        config = new Config(3,10,equip);
        setup = new Setup(config);
        runTestsQuiet(config, setup, config.getMeeting());
        
        /* 
         * Find start times and scores, for a meeting with the following attributes:
         * =========================================================================
         *  Equipment: Computer, Projector
         ** Meeting Duration: 2 Hours
         ** Meeting Attendance: 40
         *  Exclusion Set: 12:00 - 14:00
         */
        equip = new String[]{Config.EQUIP_COMPUTER, Config.EQUIP_PROJECTOR };
        config = new Config(2,40,equip);
        setup = new Setup(config);
        runTestsQuiet(config, setup, config.getMeeting());
        
        /* 
         * Find start times and scores, for a meeting with the following attributes:
         * =========================================================================
         ** Equipment: Computer, Projector, Wireless
         *  Meeting Duration: 2 Hours
         *  Meeting Attendance: 40
         ** Exclusion Set: 11:00 - 18:00
         */
        equip = new String[]{Config.EQUIP_COMPUTER, Config.EQUIP_PROJECTOR, Config.EQUIP_WIRELESS};
        config = new Config(2,40,equip);
        setup = new Setup(config);
        setup.setExclusionStart(11);
        setup.setExclusionEnd(18);
        runTestsQuiet(config, setup, config.getMeeting());
        
    }

    private void runTestsVerbose(Config config, Setup setup, Meeting meeting) {
        ArrayList<MeetingCandidate> mcList = new ArrayList<MeetingCandidate>();
        ArrayList<ExclusionRange> exList = new ArrayList<ExclusionRange>();
        ArrayList<Room> roomList = new ArrayList<Room>();
        ArrayList<ActiveParticipantPreference> appList = new ArrayList<ActiveParticipantPreference>();
        Calendar time = Calendar.getInstance();

        MeetingTimeResolver mtr = new MeetingTimeResolver(meeting, config);

        setup.createMeetingCandidates(time, mcList, appList);
        setup.createExclusionSets(time, exList);

        Debug.print("===All possible Meeting Candidates===");
        Debug.printMC(mcList);

        Debug.print("\n===Exclusion Set===");
        Debug.printEX(exList);

        setup.populateRooms(roomList);
        Debug.print("\n===Room List===");
        Debug.printRoomList(roomList);

        mtr.candidatesAreWorkingDays(mcList);
        Debug.print("\n===Candidates Validity After Working Day Rules===");
        Debug.printMC(mcList);

        mtr.cropByActiveExclusionSets(mcList, exList);
        Debug.print("\n===Candidates Validity After Exclusions===");
        Debug.printMC(mcList);

        mtr.cropByMeetingLength(mcList, config.getMeetingDuration());
        Debug.print("\n===Candidates After Cropping By Meeting Length===");
        Debug.printMC(mcList);

        mtr.scoreByActive(mcList, appList);
        Debug.print("\n===Candidates When Scored By Active===");
        Debug.printMC(mcList);

        mtr.reduceCandidatesToStartTimes(mcList);
        Debug.print("\n===Candidates Reduced to Scored Start Times===");
        Debug.printMC(mcList);

        mtr.trimByValidity(mcList);
        Debug.print("\n===Candidates Trimmed by Validity===");
        Debug.printMC_StartTimes(mcList);

        Debug.print("\n===Meeting Requirements===");
        Debug.printMeeting(meeting);

        mtr.addRoomsToMeetingCandidates(mcList, roomList);
        Debug.print("\n===Start Times And Rooms===");
        Debug.printMC_AllInfo(mcList);
    }

    private void runTestsQuiet(Config config, Setup setup, Meeting meeting) {
        ArrayList<MeetingCandidate> mcList = new ArrayList<MeetingCandidate>();
        ArrayList<ExclusionRange> exList = new ArrayList<ExclusionRange>();
        ArrayList<Room> roomList = new ArrayList<Room>();
        ArrayList<ActiveParticipantPreference> appList = new ArrayList<ActiveParticipantPreference>();
        Calendar time = Calendar.getInstance();

        MeetingTimeResolver mtr = new MeetingTimeResolver(meeting, config);

        setup.createMeetingCandidates(time, mcList, appList);
        setup.createExclusionSets(time, exList);

        setup.populateRooms(roomList);

        mtr.candidatesAreWorkingDays(mcList);

        mtr.cropByActiveExclusionSets(mcList, exList);

        mtr.cropByMeetingLength(mcList, config.getMeetingDuration());

        mtr.scoreByActive(mcList, appList);

        mtr.reduceCandidatesToStartTimes(mcList);

        mtr.trimByValidity(mcList);

        Debug.print("===Meeting Details===");
        Debug.printMeeting(meeting);

        mtr.addRoomsToMeetingCandidates(mcList, roomList);
        Debug.print("\n===Start Times And Rooms===");
        Debug.printMC_AllInfo(mcList);
    }
}
